from config_loader import ConfigLoader
from command_distributor import CommandDistributor

class CommandDistributorShell:
    def __init__(self) -> None:
        self.configloader = ConfigLoader("./config.yaml")
        self.commander = CommandDistributor(self.configloader)
    
    def loop(self):
        try:
            self.commander.connect_all()
            while True:
                command = input(">>")
                if str(command).startswith("file:"):
                    inpath = ":".join(str(command).split(":")[1:]).strip()
                    self.commander.fileupload(inpath, "")
                else:
                    self.commander.distributed_command(command)
        except KeyboardInterrupt:
            pass
        except ConnectionError:
            pass 
        finally:
            self.commander.close_all_connections()